<template>
  <ExplorationAddHeader :loading="loading" :product="product"  />
  <el-col>
    <el-tabs>
      <el-tab-pane label="基本信息">
        <ExplorationBaseInfo :product="product" />
      </el-tab-pane>
      <el-tab-pane label="产品信息">
        <ExplorationInfo :product="product" />
      </el-tab-pane>
      <el-tab-pane label="结构与配件">
        <ExplorationStructure :structure="structure" />
      </el-tab-pane>
      <el-tab-pane label="安装与图纸">
        <ExplorationInstallInfo :install="install" />
      </el-tab-pane>
      <el-tab-pane label="踏勘照片">
        <ExplorationImageInfo :product="product" />
      </el-tab-pane>
      <el-tab-pane label="操作日志">
        <OperateLogV2 :log-list="logList" />
      </el-tab-pane>
    </el-tabs>
  </el-col>
</template>
<script lang="ts" setup>
import { useTagsViewStore } from '@/store/modules/tagsView'
import { OperateLogVO } from '@/api/system/operatelog'
import * as ExplorationApi from '@/api/crm/exploration'
import ExplorationAddHeader from '@/views/crm/exploration/add/ExplorationAddHeader.vue'
import ExplorationBaseInfo from '@/views/crm/exploration/add/ExplorationBaseInfo.vue'
import ExplorationStructure from '@/views/crm/exploration/add/ExplorationStructure.vue'
import ExplorationInstallInfo from '@/views/crm/exploration/add/ExplorationInstallInfo.vue'
import ExplorationImageInfo from '@/views/crm/exploration/add/ExplorationImageInfo.vue'
import ExplorationInfo from '@/views/crm/exploration/add/ExplorationInfo.vue'
import { BizTypeEnum } from '@/api/crm/permission'
import { getOperateLogPage } from '@/api/crm/operateLog'

defineOptions({ name: 'CrmExplorationAdd' })

const route = useRoute()
const message = useMessage()
const id = route.params.id // 编号
const loading = ref(true) // 加载中
const product = ref<ExplorationApi.ExplorationVO>({
    roofCount: {
    roof: 0,
    flat: 0,
    ground: 0,
    other: 0
  },
  latitude:{
    degree: 0,
    minute: 0,
    second: 0
  },
  longitude:{
    degree: 0,
    minute: 0,
    second: 0
  }
} as ExplorationApi.ExplorationVO) // 基本信息
const install = ref<ExplorationApi.ExplorationInstallVO>({} as ExplorationApi.ExplorationInstallVO) // 安装信息
const structure = ref<ExplorationApi.ExplorationStructureVO>({} as ExplorationApi.ExplorationStructureVO) // 结构与配件



/** 获取详情 */
const getProductData = async (id: number) => {
  loading.value = true
  try {
    product.value = await ExplorationApi.getProduct(id)
    await getOperateLog(id)
  } finally {
    loading.value = false
  }
}

/** 获取操作日志 */
const logList = ref<OperateLogVO[]>([]) // 操作日志列表
const getOperateLog = async (productId: number) => {
  if (!productId) {
    return
  }
  const data = await getOperateLogPage({
    bizType: BizTypeEnum.CRM_PRODUCT,
    bizId: productId
  })
  logList.value = data.list
}

/** 初始化 */
const { delView } = useTagsViewStore() // 视图操作
const { currentRoute } = useRouter() // 路由
onMounted(async () => {
  if (id != undefined) {
    await getProductData(id)
  }
})
</script>
